<?php

namespace App\Notifications;

use App\Channels\SmsChannel;
use App\Channels\WechatChannel;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;

class OrderPaid extends Notification
{
    use Queueable;

    protected $order;

    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct($order)
    {
        $this->order = $order;
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return [WechatChannel::class,SmsChannel::class];
    }

    public function toWechat($notifiable) {

        $order = $this->order;
        $time = date("H点i分",strtotime($order->dispatch_at));
        $driver = $order->driver;
        $remark = "请于{$time}上车，上车地点：{$order->start}，车牌号:{$driver->car_no}，车型: {$driver->car_type}，司机（{$driver->name}），司机联系电话{$driver->phone}，客服联系电话。感谢您使用优客出行约车系统";


        return $message = [
            'template_id'=> config('wechat.template_id.order_paid'),
            'content'=>'',
            'url'=>route('home'),
            'data'=> [
                'first'=>'你好，你已付款成功！',
                'keyword1'=>(string)$order->paid_at,
                'keyword2'=>'优客出行',
                'keyword3'=>$order->amount,
                'keyword4'=>$order->code,
                'keyword5'=>'微信支付',
                'remark'=>$remark,
            ],
        ];

    }

    public function toSms($notifiable) {
        $order = $this->order;
        $time = date("H点i分",strtotime($order->dispatch_at));
        $driver = $order->driver;
        $remark = "请于{$time}上车，上车地点：{$order->start}，车牌号:{$driver->car_no}，车型: {$driver->car_type}，司机（{$driver->name}），司机联系电话{$driver->phone}，客服联系电话。感谢您使用优客出行约车系统";

        return $message = [
            'phone'=> $notifiable->phone,
            'content'=>$remark
        ];
    }

    /**
     * Get the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail($notifiable)
    {
        return (new MailMessage)
                    ->line('The introduction to the notification.')
                    ->action('Notification Action', url('/'))
                    ->line('Thank you for using our application!');
    }

    /**
     * Get the array representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function toArray($notifiable)
    {
        return [
            //
        ];
    }
}
